package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.domain.ArAgreement;
import net.sk.china.city.service.IArAgreementService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 协议列表Controller
 * 
 * @author gxf
 * @date 2024-04-17
 */
@Api(tags = "协议管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/user/agreement")
public class ArAgreementController extends BaseController
{
    @Autowired
    private IArAgreementService arAgreementService;

    /**
     * 查询协议列表列表
     */
    @ApiOperation("协议列表")
    @PreAuthorize("hasAnyAuthority('user:agreement:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArAgreement arAgreement)
    {
        startPage();
        List<ArAgreement> list = arAgreementService.selectArAgreementList(arAgreement);
        return getDataTable(list);
    }

    /**
     * 导出协议列表列表
     */
    @PreAuthorize("hasAnyAuthority('user:agreement:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArAgreement arAgreement)
    {
        List<ArAgreement> list = arAgreementService.selectArAgreementList(arAgreement);
//        ExcelUtil<ArAgreement> util = new ExcelUtil<ArAgreement>(ArAgreement.class);
//        util.exportExcel(response, list, "协议列表数据");
    }

    /**
     * 获取协议列表详细信息
     */
    @ApiOperation("协议详情")
    @PreAuthorize("hasAnyAuthority('user:agreement:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(arAgreementService.selectArAgreementById(id));
    }

    /**
     * 新增协议列表
     */
    @ApiOperation("新增协议")
    @PreAuthorize("hasAnyAuthority('user:agreement:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ArAgreement arAgreement)
    {
        return toAjax(arAgreementService.insertArAgreement(arAgreement));
    }

    /**
     * 修改协议列表
     */
    @ApiOperation("修改协议")
    @PreAuthorize("hasAnyAuthority('user:agreement:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ArAgreement arAgreement)
    {
        return toAjax(arAgreementService.updateArAgreement(arAgreement));
    }

    /**
     * 删除协议列表
     */
    @ApiOperation("删除协议")
    @PreAuthorize("hasAnyAuthority('user:agreement:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(arAgreementService.deleteArAgreementByIds(ids));
    }
}
